package com.ss.android.article.browser.view.multiselect;

import android.os.Handler;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.RecyclerView.Adapter;
import android.support.v7.widget.RecyclerView.ViewHolder;
import android.util.SparseBooleanArray;
import android.view.ViewGroup;

import com.ss.android.article.browser.view.multiselect.viewholder.c;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

public final class a extends Adapter {
    public int a;
    @NotNull
    public final SparseBooleanArray b;
    public int c;
    @Nullable
    public final f d;
    @NotNull
    public final d e;
    @NotNull
    private Handler f;
    @Nullable
    private RecyclerView g;
    @NotNull
    private Runnable h;
    @NotNull
    private final Adapter i;
    @Nullable
    private final List j;
    @NotNull
    private final c k;
    private final long l;

    public a(@NotNull Adapter adapter, @Nullable f arg3, @Nullable List arg4, @NotNull c decorateFactory, long arg6, d itemClickListener) {
        this.i = adapter;
        this.d = arg3;
        this.j = arg4;
        this.k = decorateFactory;
        this.l = arg6;
        this.e = itemClickListener;
        this.a = com.ss.android.article.browser.view.multiselect.g.a();
        this.b = new SparseBooleanArray();
        this.f = new Handler();
        this.h = new b(this);
    }

    public final void a() {
        int v1;
        int v0 = 0;
        int v2 = this.getItemCount() - 1;
        if (v2 >= 0) {
            v1 = 0;
            while (true) {
                this.b.put(v0, true);
                ++v1;
                if (v0 != v2) {
                    ++v0;
                    continue;
                }

                break;
            }
        } else {
            v1 = 0;
        }

        this.c = v1;
        this.notifyDataSetChanged();
    }

    public final void b() {
        int v2 = this.getItemCount() - 1;
        if (v2 >= 0) {
            int v0 = 0;
            while (true) {
                this.b.put(v0, false);
                if (v0 != v2) {
                    ++v0;
                    continue;
                }

                break;
            }
        }

        this.c = 0;
        this.notifyDataSetChanged();
    }

    public final void c() {
        this.b.clear();
        this.a = com.ss.android.article.browser.view.multiselect.g.b();
        this.notifyDataSetChanged();
        this.f.postDelayed(this.h, this.l);
    }

    public final void d() {
        if (this.a != com.ss.android.article.browser.view.multiselect.g.a()) {
            this.a = com.ss.android.article.browser.view.multiselect.g.d();
            this.f.postDelayed(this.h, this.l);
            ArrayList v1 = this.f();
            Collections.reverse(v1);
            Iterator v1_1 = v1.iterator();
            while (v1_1.hasNext()) {
                Object index = v1_1.next();
                List v2 = this.j;
                if (v2 == null) {
                    continue;
                }
                v2.remove(((Integer) index).intValue());
            }

            f v0_1 = this.d;
            if (v0_1 != null) {
                this.f();
                v0_1.b();
            }

            this.b.clear();
            this.notifyDataSetChanged();
        }
    }

    public final boolean e() {
        boolean v0;
        if (this.a == com.ss.android.article.browser.view.multiselect.g.a()) {
            v0 = false;
        } else {
            this.a = com.ss.android.article.browser.view.multiselect.g.d();
            this.notifyDataSetChanged();
            this.f.postDelayed(this.h, this.l);
            this.b.clear();
            v0 = true;
        }

        return v0;
    }

    @NotNull
    public final ArrayList f() {
        ArrayList v1 = new ArrayList();
        int v0 = 0;
        int v2 = this.getItemCount();
        while (v0 < v2) {
            if (this.b.get(v0)) {
                v1.add(Integer.valueOf(v0));
            }

            ++v0;
        }

        return v1;
    }

    public final int getItemCount() {
        return this.i.getItemCount();
    }

    public final long getItemId(int arg3) {
        return this.i.getItemId(arg3);
    }

    public final int getItemViewType(int arg2) {
        return this.i.getItemViewType(arg2);
    }

    public final void onAttachedToRecyclerView(@NotNull RecyclerView recyclerView) {
        super.onAttachedToRecyclerView(recyclerView);
        this.i.onAttachedToRecyclerView(recyclerView);
        this.g = recyclerView;
    }

    public final void onBindViewHolder(@NotNull ViewHolder viewHolder, int arg5) {
        if (!(viewHolder instanceof com.ss.android.article.browser.view.multiselect.viewholder.b)) {
            this.i.onBindViewHolder(viewHolder, arg5);
            return;
        }

        ViewHolder childHolder = ((com.ss.android.article.browser.view.multiselect.viewholder.b) viewHolder).b;
        try {
            Class v1 = ViewHolder.class;
            if (this.g == null) {
            } else {
                Field v1_1 = v1.getDeclaredField("mOwnerRecyclerView");
                v1_1.setAccessible(true);
                v1_1.set(childHolder, this.g);
            }
        } catch (Exception v0_1) {
            v0_1.printStackTrace();
        }

        this.i.bindViewHolder(((com.ss.android.article.browser.view.multiselect.viewholder.b) viewHolder).b, arg5);
        this.i.onBindViewHolder(((com.ss.android.article.browser.view.multiselect.viewholder.b) viewHolder).b, arg5);
        if (this.b.get(arg5)) {
            ((com.ss.android.article.browser.view.multiselect.viewholder.b) viewHolder).a(com.ss.android.article.browser.view.multiselect.e.b());
        } else {
            ((com.ss.android.article.browser.view.multiselect.viewholder.b) viewHolder).a(com.ss.android.article.browser.view.multiselect.e.a());
        }

        ((com.ss.android.article.browser.view.multiselect.viewholder.b) viewHolder).b(this.a);
    }

    @NotNull
    public final ViewHolder onCreateViewHolder(@NotNull ViewGroup viewGroup, int arg5) {
        ViewHolder outerHolder = this.i.onCreateViewHolder(viewGroup, arg5);
        c v1 = this.k;
        return v1.a(outerHolder, this);
    }

    public final void onDetachedFromRecyclerView(@NotNull RecyclerView recyclerView) {
        super.onDetachedFromRecyclerView(recyclerView);
        this.i.onDetachedFromRecyclerView(recyclerView);
        this.g = recyclerView;
    }

    public final boolean onFailedToRecycleView(@Nullable ViewHolder arg2) {
        super.onFailedToRecycleView(arg2);
        return this.i.onFailedToRecycleView(arg2);
    }

    public final void onViewRecycled(@NotNull ViewHolder holder) {
        super.onViewRecycled(holder);
        this.i.onViewRecycled(holder);
    }

    public final void setHasStableIds(boolean arg2) {
        super.setHasStableIds(arg2);
        this.i.setHasStableIds(arg2);
    }
}

